//---------------------------------------------------------------------------
#ifndef CRibH
#define CRibH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include "CEdit.h"
#include "CtrlStd.h"
//---------------------------------------------------------------------------
#define LONGUEUR_DESIGNATION_RIB 25
#define LONGUEUR_BANQUE_RIB       5
#define LONGUEUR_GUICHET_RIB      5
#define LONGUEUR_COMPTE_RIB      11
#define LONGUEUR_CLE_RIB          2

#define FORMER_RIB(Designation,Banque,Guichet,Compte,cle) (Designation + "#" + Banque + "#" + Guichet + "#" + Compte + "#" + cle)
#define RIB_VIDE "####"


class PACKAGE_CTRLSTD CRib : public TCustomPanel
{
private:
  CEdit *m_pDesignation;
  CEdit *m_pBanque;
  CEdit *m_pGuichet;
  CEdit *m_pNumCpt;
  CEdit *m_pRIB;
  int    m_nLeft;
  bool   m_bReadOnly;
  bool   m_bEnabled;
  bool   m_MessageErreur;

  void __fastcall InitComposantInterne( CEdit **pIntEdit, int nMaxChar, const AnsiString &strLabel, CEdit::FiltresEdit eFiltre);

  AnsiString __fastcall GetDesignation( void) const { return m_pDesignation->Text; };
  AnsiString __fastcall GetBanque     ( void) const { return      m_pBanque->Text; };
  AnsiString __fastcall GetGuichet    ( void) const { return     m_pGuichet->Text; };
  AnsiString __fastcall GetCompte     ( void) const { return      m_pNumCpt->Text; };
  AnsiString __fastcall GetRib        ( void) const { return         m_pRIB->Text; };

  void __fastcall SetDesignation  ( const AnsiString &strValue) { m_pDesignation->Text = strValue; };
  void __fastcall SetBanque       ( const AnsiString &strValue) {      m_pBanque->Text = strValue; };
  void __fastcall SetGuichet      ( const AnsiString &strValue) {     m_pGuichet->Text = strValue; };
  void __fastcall SetCompte       ( const AnsiString &strValue) {      m_pNumCpt->Text = strValue; };
  void __fastcall SetRib          ( const AnsiString &strValue) {         m_pRIB->Text = strValue; };

  AnsiString __fastcall GetDomiciliation( void) const;
  void       __fastcall SetDomiciliation( const AnsiString &strValue);

  AnsiString __fastcall ConvAlpha2Numeric( const AnsiString &strValue) const;
  int        __fastcall CalculRIB( void) const;

  void       __fastcall SetReadOnly( bool bValue);
  void       __fastcall SetEnabled ( bool bValue);
  bool       __fastcall GetIsValide( void) const;
  bool       __fastcall GetIsEmpty( void) const;

protected:
  DYNAMIC void __fastcall DoExit( void);

  #define COMPLETER(chaine,taille) if (!chaine.IsEmpty() && (chaine.Length() < taille)) \
                                     chaine = AnsiString::StringOfChar('0',taille - chaine.Length()) + chaine; \
                                   return chaine

public:
  __fastcall CRib(TComponent* Owner);
  virtual void __fastcall SetFocus(void);

  __property AnsiString Designation   = { read=GetDesignation  , write=SetDesignation   };
  __property AnsiString Banque        = { read=GetBanque       , write=SetBanque        };
  __property AnsiString Guichet       = { read=GetGuichet      , write=SetGuichet       };
  __property AnsiString Compte        = { read=GetCompte       , write=SetCompte        };
  __property AnsiString Rib           = { read=GetRib          , write=SetRib           };
  __property AnsiString Domiciliation = { read=GetDomiciliation, write=SetDomiciliation };

  __property bool IsValide = { read=GetIsValide };
  __property bool IsEmpty = { read=GetIsEmpty };
  __property bool AfficherMessageErreurEnAutomatique = { read=m_MessageErreur, write=m_MessageErreur, default=1};

  static AnsiString & __fastcall CompleterBanque(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_BANQUE_RIB);}
  static AnsiString & __fastcall CompleterGuichet(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_GUICHET_RIB);}
  static AnsiString & __fastcall CompleterCle(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_CLE_RIB);}
  static AnsiString & __fastcall CompleterNumCompte(AnsiString &Chaine){COMPLETER(Chaine,LONGUEUR_COMPTE_RIB);}

__published:
  __property Font;
  __property Height = { stored=false };
  __property Width  = { stored=false };
  __property ParentFont;
  __property bool ReadOnly = { read=m_bReadOnly, write=SetReadOnly, default=0 };
  __property bool Enabled  = { read=m_bEnabled , write=SetEnabled , default=1 };
  __property Visible;
};
//---------------------------------------------------------------------------
// Déclaration des fonctions pouvant être appelées de l'extérieur
extern PACKAGE_CTRLSTD AnsiString  __fastcall CalculerIBAN(const AnsiString &pBanque, const AnsiString &pGuichet, const AnsiString &pCompte, const AnsiString &pCle);
#endif
